using Magiq.Delete;

namespace Magiq.Sql {
  public class MagiqToSqlDeleteProvider : IDeleteProvider {
    #region IDeleteProvider Members

    public int Execute<T>(IQueryableDelete<T> delete) where T : class {
      var dataContext = delete.Where.DataContext();
      var queryExecutor = new DeleteExecutor(dataContext, delete.Where);
      var from = queryExecutor.BaseWhereClause;
      var deleteSql = "DELETE " + queryExecutor.BaseTableName + " FROM " + from;

      var result = queryExecutor.ExecuteNonQuery(deleteSql);
      return result;
    }

    #endregion
  }
}